package com.xuzhijie.pms.controller;


import cn.hutool.core.bean.BeanUtil;
import com.xuzhijie.pms.common.Result;
import com.xuzhijie.pms.entity.Property;
import com.xuzhijie.pms.entity.Vehicle;
import com.xuzhijie.pms.entity.dto.PetDto;
import com.xuzhijie.pms.entity.dto.vehicleDto;
import com.xuzhijie.pms.entity.vo.PropertyVo;
import com.xuzhijie.pms.entity.vo.VehicleVo;
import com.xuzhijie.pms.service.IVehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 许志杰
 * @since 2024-02-17
 */
@RestController
@RequestMapping("/vehicle")
public class VehicleController {

    @Autowired
    private IVehicleService service;

    @GetMapping("/page")
    public Result findPage(@RequestParam Integer page,
                           @RequestParam Integer size,
                           @RequestParam Integer vehicleCategory,
                           @RequestParam Integer isNewEnergy,
                           @RequestParam Integer isBinding,
                           @RequestParam Integer syncStatus,
                           @RequestParam String licensePlateNumber) {

        return service.findPage(page, size, vehicleCategory, isNewEnergy, isBinding, syncStatus, licensePlateNumber);
    }

    @PutMapping("/unbinding")
    public Result unbindingVehicle(@RequestBody String id) {
        return service.unbindingProperty(id);
    }

    @PostMapping("/create")
    public Result createVehicle(@RequestBody vehicleDto vehicleDto) {
        return service.createVehicle(vehicleDto);
    }

    @GetMapping("/vehicleById")
    public Result vehicleById(@RequestParam String id) {
        Vehicle byId = service.getById(id);
        return Result.success(byId);
    }

    @GetMapping("/wx-getByOwnerId")
    public Result getByOwnerId(@RequestParam String id) {
        return service.getByOwnerId(id);
    }

    @GetMapping("/wx-getVehicleById")
    public Result wxGetVById(@RequestParam String id) {
        Vehicle vehicle = service.getById(id);
        VehicleVo vehicleVo = new VehicleVo(vehicle);
        BeanUtil.copyProperties(vehicle, vehicleVo, "images");

        return Result.success(vehicleVo);
    }
}

